home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!milyng
- From: mikael@pobox.com (Mikael Lyngvig)
- Subject: Re: Help(link error)
- Message-ID: <milyngDM8Ho8.JJI@netcom.com>
- Sender: milyng@netcom9.netcom.com
- Organization: Hacker's Paradise, Inc.
- X-Newsreader: WinVN 0.99.7
- References: <4es3j2$3e2@news-e2a.gnn.com>
- Date: Sun, 4 Feb 1996 04:26:32 GMT
-
- In article <4es3j2$3e2@news-e2a.gnn.com>, GaryJ@gnn.com says...
- >
- >Hi,
- > I am trying to compile a 2 file program plus a header file
- > using MSVC++ 1.52.I am having a problem with link error
- >2025. I am using an array of structures called golf with a
- >variable g.Error 2025 says that struct golf_near* g near is
- >defined more than once.I would appreciate any help I could
- >get.
-
- Sounds like you're defining the array in the header file and include it in
- both source files. The correct way to do this is:
-
- /* header.h */
- extern golf g[GOLF_COUNT];
-
-
- /* source1.c */
- #include "header.h"
-
- golf g[GOLF_COUNT]; /* actual definition - allocates memory */
-
-
- /* source2.c */
- #include "header.h"
-
- /* do nothing - golf is already defined by the header */
-
-
- An alternate method, which you may need to use because some compiler complain,
- is to do:
-
- /* header.h */
-
- #define GOLF_SIZE 100
-
-
- /* source1.c */
-
- golf g[GOLF_COUNT]; /* actual definition - allocates memory */
-
-
- /* source2.c */
-
- extern golf g[GOLF_COUNT];
-
-
- Most of all, the problem seems to be that you have a global variable.
- Consider defining and accessing g in one module only and let the other module
- access g through the first module (using access functions).
-
-
- Mikael
-
-
-